#include "Builder.h"

///////////////////
void Product::AddPart(const string& part)
{
	_parts.push_back(part);
}

void Product::Show() const
{
	list<string>::const_iterator citer = _parts.begin();

	cout << "Product:";
	for(;citer != _parts.end();citer++)
	{
		cout << *citer << ",";
	}
	cout << endl;
}

/////////////////////////////////////////
ConcreteBuilderA::ConcreteBuilderA()
	:_product(NULL)
{
	_product = new Product;
}

void ConcreteBuilderA::AddPartA()
{
	_product->AddPart("AAAA PartA");
}
void ConcreteBuilderA::AddPartB()
{
	_product->AddPart("AAAA PartB");
}
void ConcreteBuilderA::AddPartC()
{
	_product->AddPart("AAAA PartC");
}
Product* ConcreteBuilderA::GetProduct()
{
	return _product;
}

////////////////////////////////////
ConcreteBuilderB::ConcreteBuilderB()
	:_product(NULL)
{
	_product = new Product;
}

void ConcreteBuilderB::AddPartA()
{
	_product->AddPart("BBBB PartA");
}
void ConcreteBuilderB::AddPartB()
{
	_product->AddPart("BBBB PartB");
}
void ConcreteBuilderB::AddPartC()
{
	_product->AddPart("BBBB PartC");
}
Product* ConcreteBuilderB::GetProduct()
{
	return _product;
}

////////////////////////////////
void Director::Construct(IBuilder* builder)
{
	_builder = builder;
	
	_builder->AddPartA();
	_builder->AddPartB();
	_builder->AddPartC();
}

int main()
{
	Director director;
	ConcreteBuilderA conBuildA;
	ConcreteBuilderB conBuildB;

	director.Construct(&conBuildA);
	Product *pA = conBuildA.GetProduct();

	director.Construct(&conBuildB);
	Product *pB = conBuildB.GetProduct();	

	pA->Show();
	pB->Show();

	delete pA;
	delete pB;
}
